/*
 * @Author: 小粽子
 * @Date: 2017-12-11 19:05:08
 * @Last Modified by: 小粽子
 * @Last Modified time: 2017-12-11 20:41:00
 */
import _ from 'lodash';
import printMe from './print.js';
import './styles.css';

function component() {
    var element = document.createElement('div');
    var btn = document.createElement('button');

    element.innerHTML = _.join([
        'Hello', 'webpack'
    ], ' ');

    btn.innerHTML = 'Click me and check the console!';
    btn.onclick = printMe;

    element.appendChild(btn);

    return element;
}

let element = component(); // Store the element to re-render on print.js changes
document
    .body
    .appendChild(element);

if (module.hot) {
    module
        .hot
        .accept('./print.js', function () {
            console.log('Accepting the updated printMe module!');
            document
                .body
                .removeChild(element);
            element = component(); // Re-render the "component" to update the click handler
            document
                .body
                .appendChild(element);
        })
}